﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace CodeBuilder2.BLL.Scanner
{
    class PortScanner
    {
        public bool Scan(string targetName,int port)
        {
            bool isConnected = false;

            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                s.Connect(targetName, port);
                //IPAddress ip = IPAddress.Parse("192.168.1.1");
                //s.Connect(ip, 80);
                if (s.Connected)
                {
                    isConnected = true;
                }
            }
            catch (Exception ex)
            {
                isConnected = false;
                throw ex;
            }
            finally
            {
                s.Close();
            }
            return isConnected;
        }
    }
}
